package com.ruoyi.merchant.controller;

import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.dto.MerchantRegionBindingDTO;
import com.ruoyi.merchant.domain.vo.MerchantRegionBindingVO;
import com.ruoyi.merchant.service.IMerchantRegionBindingService;

/**
 * 商家区域绑定Controller
 * 
 * @author xperia
 */
@RestController
@RequestMapping("/merchant/region/binding")
public class MerchantRegionBindingController extends BaseController {
    
    @Autowired
    private IMerchantRegionBindingService merchantRegionBindingService;

    /**
     * 查询区域绑定列表
     */
    @GetMapping("/list")
    public AjaxResult list() {
        List<MerchantRegionBindingVO> list = merchantRegionBindingService.selectBindingList();
        return success(list);
    }

    /**
     * 查询区域绑定详情
     */
    @GetMapping("/{bindingId}")
    public AjaxResult getInfo(@PathVariable Long bindingId) {
        return success(merchantRegionBindingService.selectBindingById(bindingId));
    }

    /**
     * 新增区域绑定
     */
    @Log(title = "区域绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody MerchantRegionBindingDTO dto) {
        return toAjax(merchantRegionBindingService.insertBinding(dto));
    }

    /**
     * 修改区域绑定
     */
    @Log(title = "区域绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody MerchantRegionBindingDTO dto) {
        return toAjax(merchantRegionBindingService.updateBinding(dto));
    }

    /**
     * 启用区域绑定
     */
    @Log(title = "启用区域绑定", businessType = BusinessType.UPDATE)
    @PutMapping("/enable/{bindingId}")
    public AjaxResult enable(@PathVariable Long bindingId) {
        return toAjax(merchantRegionBindingService.enableBinding(bindingId));
    }

    /**
     * 禁用区域绑定
     */
    @Log(title = "禁用区域绑定", businessType = BusinessType.UPDATE)
    @PutMapping("/disable/{bindingId}")
    public AjaxResult disable(@PathVariable Long bindingId) {
        return toAjax(merchantRegionBindingService.disableBinding(bindingId));
    }

    /**
     * 删除区域绑定
     */
    @Log(title = "区域绑定", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bindingId}")
    public AjaxResult remove(@PathVariable Long bindingId) {
        return toAjax(merchantRegionBindingService.deleteBinding(bindingId));
    }
}

